﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using papercut2.Data.Global;

namespace papercut2.Data.Pic
{
    class pic
    {
        private static LinkedList<bpoint> PstartList = null;
        public static bool isVisuable = true;
        public static bool isFocus = false;//选择哪一个图形
        private static Color c = Color.FromArgb(0, 0, 0);//black，change later......
        public static int len = 0;//角点方框的长度的一半
        public static int X = 0, Y = 0;//图案参考点
        public pic()
        {
        }
        public bool loadpicture(LinkedList<bpoint> point)
        {
            if (point == null) return false;
            PstartList = point;
            X = PstartList.First.Value.X;
            Y = PstartList.First.Value.Y;
            return true;
        }
        public void Draw()
        {
        }

        public void Move(int x, int y)
        {
            if (PstartList == null) return;
            //坐标相对化
            relativelization(X, Y, x, y);
            //移动参考点\
            X = PstartList.First.Value.X;
            Y = PstartList.First.Value.Y;
        }

        //............need you to implement......................
        private static void relativelization(int oldX, int oldY, int newX, int newY)
        {
            //将坐标相对化，取链表的开始点作为参考点....................
            //add you code.......
            int disX = newX - oldX;
            int disY = newX - oldY;
            LinkedListNode<bpoint> tempstart = PstartList.First;
            while (tempstart != null)
            {
                bpoint temp = tempstart.Value;
                while (temp != null)
                {
                    temp.X += disX;
                    temp.Y += disY;
                    temp = temp.Next;
                }
                tempstart = tempstart.Next;
            }
        }


        public void Delete()
        {
            //..........析构链表................

        }
        public void Zoom(double n)//放大倍数
        {
            if (PstartList == null || n < 0) return;

            LinkedListNode<bpoint> tempStart = PstartList.First;
            while (tempStart != null)
            {
                bpoint temp = tempStart.Value;
                while (temp != null)
                {

                    //..change the coordinate..........
                    int laterX = (int)n * (temp.X - X);
                    int laterY = (int)n * (temp.Y - Y);
                    //.........set the coordinate........
                    temp.X = laterX;
                    temp.Y = laterY;
                    //........next node..
                    temp = temp.Next;
                }
                tempStart = tempStart.Next;
            }
        }
        public void Rotate(double angle)
        {
            if (PstartList == null) return;

        }
        //............set and get function,................
        public LinkedList<bpoint> getPstartList() { return PstartList; }

    }
}
